def use_tuple():
    info_tuple = ("zhangsan", 18, 1.75, 'zhangsan')
    for i in info_tuple:
        print(i)

    print(info_tuple.index("zhangsan"))
    print(info_tuple.count("zhangsan"))
    print(len(info_tuple))
# use_tuple()


def use_str():
    info_tuple = ("小明", 21, 1.85)
    print("%s年龄是%d身高是%.2f"%info_tuple)
    info_str="%s年龄是%d身高是%.2f"%info_tuple
    print(info_str)
    print(f"使用f{info_tuple}")
# use_str()


def use_dict_base():
    xiaoming_dict={"name": "小明"}
    print(id(xiaoming_dict))
    # 1.取值
    print(xiaoming_dict['name'])
    # 2.增加修改
    xiaoming_dict['age'] = 18
    print(xiaoming_dict)
    xiaoming_dict['name']="小王"
    print(xiaoming_dict)
    xiaoming_dict['name']="小明"
    # 3.删除
    del xiaoming_dict['name']
    print(xiaoming_dict)
    # 4.统计键对值数量
    print(len(xiaoming_dict))
    # 5.合并
    temp_dict={"height":1.75,"age":20}
    xiaoming_dict.update(temp_dict)
    print(xiaoming_dict)
    xiaoming_dict.clear()
    print(xiaoming_dict)
# use_dict_base()


def use_dict_iter():
    card_dict={"name": "小明",
               "qq": "123456",
               "phone": "10086"}
    for i in card_dict:
        print(i)
    for k in card_dict.keys():
        print(k)
    for v in card_dict.values():
        print(v)
    for k,v in card_dict.items():
        print(k,v)
    for k in card_dict:
        print(k,card_dict[k])
# use_dict_iter()


def use_list_dict():
    card_list = [
        {"name": "张三",
         "qq": "12345",
         "phone": "110"},
        {"name": "李四",
         "qq": "54321",
         "phone": "10086"}
    ]
    for card in card_list:
        print(card)
# use_list_dict()


def check_type():
    s1 = 'abc*'
    print(s1.isalnum())        #全为数字或者字符
    s2 = '123'
    print(s2.isdecimal())      #全为数字
# check_type()


def str_find():
    s1 = 'abcdefgcdef'
    print(s1.find('cd',3))
    s2 = s1.replace('cd', 'CD', 1)
    print(s2)
# str_find()


def str_split_join():
    s1 = 'abc bcd 我很帅'
    print(s1.split())
    s1 = 'abc,bcd,我很帅'
    print(s1.split(','))
    s2 = 'abc\nbcd\nefg'
    print(s2.splitlines())

    s3 = 'abc\r\nbcd\r\nefg'
    print(s3.splitlines(True))
    str_list = ['a', 'b', 'c', 'd']
    print(str_list)
    print(','.join(str_list))
# str_split_join()


def str_slice():
    num_str = "0123456789"
    # 1. 截取从 2 ~ 5 位置 的字符串
    print(num_str[2:6])

    # 2. 截取从 2 ~ `末尾` 的字符串
    print(num_str[2:])

    # 3. 截取从 `开始` ~ 5 位置 的字符串
    print(num_str[:6])

    # 4. 截取完整的字符串
    print(num_str[:])

    # 5. 从开始位置，每隔一个字符截取字符串
    print(num_str[::2])

    # 6. 从索引 1 开始，每隔一个取一个
    print(num_str[1::2])

    # 倒序切片
    # -1 表示倒数第一个字符
    print(num_str[-1])

    # 7. 截取从 2 ~ `末尾 - 1` 的字符串
    print(num_str[2:-1])

    # 8. 截取字符串末尾两个字符
    print(num_str[-2:])

    # 9. 字符串的逆序（面试题）
    print(num_str[::-1])
# str_slice()


def index_count():
    hello_str = "heallo hello"

    # 1. 统计字符串长度
    print(len(hello_str))

    # 2. 统计某一个小（子）字符串出现的次数
    print(hello_str.count("llo"))
    print(hello_str.count("abc"))

    # 3. 某一个子字符串出现的位置
    print(hello_str.index("llo"))
# index_count()


def use_set():
    set1 = set()  # 定义一个空集合
    print(type(set1))

    set2 = {1, 2, 3, 4, 5}

    fruits = {"apple", "banana", "cherry"}
    fruits.add("orange")
    print(fruits)

    fruits = {"apple", "banana", "cherry"}
    x = fruits.copy()
    print(id(x))
    print(id(fruits))

    x = {"apple", "banana", "cherry"}
    y = {"google", "microsoft", "apple"}
    z = x.difference(y)
    print(f'差集{z}')

    x = {"apple", "banana", "cherry"}
    y = {"google", "microsoft", "apple"}
    x.difference_update(y)
    print(x)
    print('-' * 50)
    fruits = {"apple", "banana", "cherry"}
    fruits.discard("banana")
    print(fruits)
    print('-' * 50)
    x = {"a", "b", "c"}
    y = {"c", "d", "e"}
    z = {"f", "g", "c"}
    result = x.intersection(y, z)
    print(result)
    print('-' * 50)
    x = {"apple", "banana", "cherry"}
    y = {"google", "runoob", "apple"}
    z = x.symmetric_difference(y)
    print(z)
    print('-' * 50)
    x = {"apple", "banana", "cherry"}
    y = {"google", "runoob", "apple"}
    z = x.union(y)
    print(z)

    print('apple' in z)

    print(x - y)
    print(x | y)
    print(x & y)
    print(x ^ y)
use_set()


def test1(name,age=6):
    print(name,age)


test1('xiaoming','han')


def test2(age=6,name):       #报错，缺省参数得放前面
    print(age,name)


test2("han","xiaoming")


